package com.linsen.erp.admin.controller;


import com.linsen.erp.admin.provider.dto.DeptDTO;
import com.linsen.erp.admin.provider.vo.DeptVO;
import com.linsen.erp.admin.service.IDeptService;
import com.linsen.core.common.util.ConvertUtil;
import com.linsen.core.common.util.Result;
import com.linsen.core.log.annotation.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author zhaoyong
 * @since 2023-07-24
 */
@RestController
@RequestMapping("/admin/dept")
@RequiredArgsConstructor
@Api(tags = "部门管理")
public class DeptController {
    private final IDeptService iDeptService;

    @GetMapping("/list")
    @ApiOperation(value = "部门列表", response = DeptVO[].class)
    public Result list(){
        return Result.data(iDeptService.getDeptList());
    }

    @GetMapping("info")
    @ApiImplicitParam(name = "id", value = "部门id", required = true, dataType = "string")
    @ApiOperation(value = "部门详情",response = DeptVO.class)
    public Result get(@ApiIgnore @RequestParam(value = "id") String id) {
        return Result.data(iDeptService.get(id));
    }

    //@SaCheckPermission("admin:dept:save")
    @Log(value = "新增部门")
    @PostMapping("save")
    @ApiOperation("新增部门")
    public Result save(@RequestBody DeptDTO deptDTO) {
        iDeptService.saveDept(deptDTO);

        return Result.ok();
    }

    //@SaCheckPermission("admin:dept:update")
    @Log(value = "修改部门")
    @PostMapping("update")
    @ApiOperation("修改部门")
    public Result update(@RequestBody DeptDTO deptDTO) {
        iDeptService.updateDept(deptDTO);

        return Result.ok();
    }

    //@SaCheckPermission("admin:dept:delete")
    @Log(value = "删除部门")
    @PostMapping("delete")
    @ApiImplicitParam(name = "id", value = "部门id", required = true, dataType = "string")
    @ApiOperation("删除部门")
    public Result delete(@ApiIgnore @RequestParam("id") String id) {
        iDeptService.delete(id);

        return Result.ok();
    }
}
